import { createI18n } from 'vue-i18n'
import zhCN from './lang/zh-CN'
import enUS from './lang/en-US'
import frFR from './lang/fr-FR'
import { getLanguage } from '@/utils/storage'

// 获取浏览器语言
const getBrowserLanguage = () => {
  const language = navigator.language
  if (language.includes('zh')) return 'zh-CN'
  if (language.includes('fr')) return 'fr-FR'
  return 'en-US'
}

// 获取存储的语言或浏览器语言
const getLocale = () => {
  const storedLanguage = getLanguage()
  return storedLanguage || getBrowserLanguage()
}

const messages = {
  'zh-CN': zhCN,
  'en-US': enUS,
  'fr-FR': frFR,
}

const i18n = createI18n({
  legacy: false, // 使用组合式API
  locale: getLocale(),
  fallbackLocale: 'zh-CN',
  messages,
  silentTranslationWarn: true,
  silentFallbackWarn: true,
})

export default i18n 